import java.util.ArrayList;
import java.util.List;
//https://leetcode.cn/problems/subsets/
class Solution {
    List<List<Integer>> ret;
    List<Integer> path;

    public List<List<Integer>> subsets(int[] nums) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        dfs(nums, 0);
        return ret;
    }

    public void dfs(int[] nums, int pos) {
        ret.add(new ArrayList<>(path));

        if (pos >= nums.length)
            return;

        for (int i = pos; i < nums.length; i++) {
            path.add(nums[i]);
            // 从当前位置依次向后枚举
            dfs(nums, i + 1);
            path.remove(path.size() - 1);// 回溯 -> 恢复现场
        }
    }
}